package com.shareroad.dubboweb.frame.dao.data;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.shareroad.dubboweb.frame.dao.po.DubboInterfacePO;
import com.shareroad.dubboweb.frame.dao.po.DubboMethodPO;
import com.shareroad.dubboweb.frame.dao.po.DubboParamPO;
import com.shareroad.dubboweb.frame.dao.po.DubboWebPO;

public class DubboWebData {
	private static List<DubboWebPO> dubboWebDataList = new ArrayList<DubboWebPO>();
	
	public static List<DubboWebPO> getAllData(){
		return dubboWebDataList;
	}
	
	public static void addData(DubboWebPO dubboWebPO){
		dubboWebDataList.add(dubboWebPO);
	}
	
	
	public static DubboWebPO getDataByJarName(String jarName){
		for(DubboWebPO dubboWebPO : dubboWebDataList){
			if(jarName.equals(dubboWebPO.jarName)){
				return dubboWebPO;
			}
		}
		return null;
	}
	
	public static List<DubboParamPO> getParamTypes(String interfaceName,String methodName){
		
		for(DubboWebPO dubboWeb : dubboWebDataList){
			for(DubboInterfacePO dubboInterface :dubboWeb.dubboInterfaceList){
				if((dubboInterface.interfaceName).equals(interfaceName)){
					for(DubboMethodPO dubboMethod : dubboInterface.dubboMethodList){
						if(dubboMethod.methodName.equals(methodName)){
							List<DubboParamPO> lst = new ArrayList<DubboParamPO>();
							for(DubboParamPO dubboParam :dubboMethod.dubboParamList){
								lst.add(dubboParam);
							}
							return lst;
						}
					}
				}
			}
		}
		return null;
	}
	
	public static DubboWebPO getDubboWeb(String interfaceName,String methodName){
			for(DubboWebPO dubboWeb : dubboWebDataList){
				for(DubboInterfacePO dubboInterface :dubboWeb.dubboInterfaceList){
					if((dubboInterface.interfaceName).equals(interfaceName)){
						for(DubboMethodPO dubboMethod : dubboInterface.dubboMethodList){
							if(dubboMethod.methodName.equals(methodName)){
								return dubboWeb;
							}
						}
					}
				}
			}
			return null;
		}
	
	
	public static void main(String[] args){
		System.out.println(JSON.toJSONString(DubboWebData.getAllData()));
	}

}
